package com.wnxy.consumer.controller;


import com.wnxy.common.model.Student;
import com.wnxy.feign.stu.api.StuApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author yellow Doctor
 * @date 2025-03-21
 * @desc 蜗牛创想：www.woniuxy.com
 */
@RestController
@RequestMapping("/consumer/stu")
public class StudentConsumerController {

    //引入 client-api 远程调用
    @Autowired
    private StuApi stuApi;

    /**
     *
     * 熔断器：
     *      a服务器调用b服务器
     *      b服务器出现问题 返回一个默认的结果 这就是服务降级
     *
     *
     *
     * @param id
     * @return
     */

    @GetMapping("/{id}")
    public Student getStudentById(@PathVariable("id") int id) {

        //以前调用service 获取数据
        //现在通过 openfeign 调用
        System.out.println("我是服务消费者..." + id);
        Student stu = stuApi.getStudentById(id);
        return stu;
    }

    @PostMapping
    public void saveStudent(@RequestBody Student student){

        stuApi.saveStudent(student);

    }

    @PutMapping
    public void updateStudent(@RequestBody Student student){

        stuApi.updateStudent(student);

    }

}
